// pagesEnterprise/pages/parkManage/parkManage.js
import ajax from '../../../utils/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    parkId: '',
    cardId: '',
    statistics: '',
    modeIndex: null,
    /**
     * 园区对象
     */
    parkEntity: null
  },
  parkDetailsEvent() {
    const { checkStatus, id } = this.data.parkEntity
    if (checkStatus == 1) return ajax.showToast('审核中')
    wx.navigateTo({ url: `/pagesEnterprise/pages/parkInfoDetails/parkInfoDetails?id=${id}` })
  },
  modeEvent() {
    let modeIndex = this.data.modeIndex += 1
    if (modeIndex > 3) {
      modeIndex = null;
      wx.setStorageSync('garden-guidance', true)
    }
    this.setData({ modeIndex })
  },
  navigator(event) {
    console.log(event)
    const url = event.currentTarget.dataset.url
    const { parkId, cardId } = this.data
    if (!url) return ajax.showToast('开发中...')
    const str = url.indexOf('?') == -1 ? '?' : '&'
    wx.navigateTo({
      url: `${url}${str}id=${parkId}&cardId=${cardId}`
    })
  },
  /**
   * 获取园区详情信息
   */
  async getParkDetails() {
    const userInfo = wx.getStorageSync('userInfo')
    const res = await ajax.get(`/garden/info?id=${userInfo.roles.park_id}`)
    this.get_back_park_sum(userInfo.roles.park_id)
    this.setData({ parkEntity: res.data })
  },
  /**
   * 接口 - 数据统计
   */
  get_back_park_sum: function (park_id) {
    let that = this
    ajax.get('/wx/appletRecord/gardenSum', {
      gardenId: park_id
    }).then(res => {
      if (res.code == 200) {
        that.setData({
          statistics: res.data
        })
      }
    })
  },

  route: function (e) {
    let index = parseInt(e.currentTarget.id)
    console.log(index)

    //特殊拦截
    if (index == 9) { //海报裂变
      wx.switchTab({
        url: '/pages/share/share',
      })
      return
    }

    let page = ''
    switch (index) {
      case 1: //信息修改
        page = '/pages/mine/park-manage/info/edit'
        break
      case 2: //名片编辑
        page = '/pages/mine/park-manage/card/edit'
        break
      case 3: //房源维护
        page = '/pages/mine/park-manage/house/list'
        break
      case 4: //新闻发布
        page = '/pages/mine/park-manage/news/list'
        break
      case 5: //看房工单
        page = '/pages/mine/park-manage/work/list'
        break
      case 6: //裂变团队
        page = '/pages/mine/share/share'
        break
      case 7: //客户管理
        page = '/pages/mine/park-manage/customer/customer'
        break
      case 8: //金融服务
        page = '/pages/mine/park-manage/serve/serve'
        break
      case 10: //邀请入驻
        page = '/pages/park/company/edit/intro'
        break
      case 11: //营销活动
        page = '/pages/home/marketing/marketing'
        break
    }
    wx.navigateTo({
      url: page + '?id=' + this.data.parkId + '&cardId=' + this.data.cardId,
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this.setData({
    //   parkId: options.id,
    //   cardId: options.cardId,
    // })
    // this.get_back_park_sum()
    this.getParkDetails()
    // this.setData({
    //   modeIndex: wx.getStorageSync('garden-guidance') ? null : 1
    // })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    const userInfo = wx.getStorageSync('userInfo')
    return {
      imageUrl: 'https://file.yledanpei.com/2021/09/23/414e36f2-8d60-4829-bfce-9b47d1a95ebd.png',
      title: `${userInfo.nickName}-邀请您企业入驻`,
      path: `/pagesEnterprise/pages/enterpriseAuthentication/enterpriseAuthentication?shareId=${userInfo.id}`
    }
  }
})